/* 
 * 
 * Created on 17 Oct 2011 by simonk
 * 
 * Copyright: Multicom Products Ltd. 2011 Bristol, England
 */
package gui.controllers;

import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JTable;

import gui.GUIUtils;
import gui.JobStatuses;
import gui.main.MainPanelGUIView;
import objects.data.WorkPacket;

/**
 *
 * @author simonk
 */
public class JobPanelController implements JobStatuses{
	private static Map<String,Integer> tablePositions = new HashMap<String,Integer>(); 
	private static Vector<Vector> rows = new Vector<Vector>();
	private static Vector<String> cols = new Vector<String>();
	
	public static Vector<Vector> getRows() {
		return rows;
	}
	public static Vector<String> getCols() {
		if(cols.isEmpty()) {
			cols.add("Timestamp");
			cols.add("Jobname");
			cols.add("File");
			cols.add("Status");
			cols.add("Execution time");
			cols.add("Command");
			cols.add("Cancel job");
		}
		return cols;
	}
	
	@SuppressWarnings("unchecked")
	public static void insertJob(WorkPacket wp) {
		JTable table = MainPanelGUIView.jobsTable;
		Vector data = new Vector<String>();
		data.add(wp.timestamp);
		data.add(wp.jobname);
		data.add(wp.sourceDir);
		data.add(wp.status);
		data.add("n/a");
		data.add(wp.executable);
		data.add(new JButton("Cancel"));
		rows.add(data);
		table.addNotify();
		table.revalidate();
		tablePositions.put(wp.uniqueId,rows.size());
	}
	
	public static void setJobList(WorkPacket wp) {
		JList list = GUIUtils.MainPanel.jobsList;
		DefaultListModel model = (DefaultListModel)list.getModel();
		model.removeAllElements();
		model.add(0, "Timestamp: "+wp.timestamp);
		model.add(1, "Jobname: "+wp.jobname);
	}
}
